package com.example.everying.service.appeal.impl;/*
 * 项目名称: everything
 * 文件名: AppealRecordServiceImpl
 * 作者: 张泽阳
 * 日期: 2025/6/20
 * 描述:
 */

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.everying.mapper.appeal.AppealRecordMapper;
import com.example.everying.model.dto.appeal.AddAppealDto;
import com.example.everying.model.dto.appeal.AppealRecordPageDto;
import com.example.everying.model.entity.appeal.AppealRecord;
import com.example.everying.model.vo.appeal.AppealRecordPageVo;
import com.example.everying.service.appeal.AppealRecordService;
import com.example.everying.utils.Result;
import org.springframework.stereotype.Service;

@Service
public class AppealRecordServiceImpl extends ServiceImpl<AppealRecordMapper, AppealRecord> implements AppealRecordService {
    @Override
    public AppealRecord getAppealByArticleIdAndUserId(AddAppealDto addAppealDto) {
        AppealRecord appealRecord = new AppealRecord();
        appealRecord.setArticleId(addAppealDto.getArticleId());
        appealRecord.setAppealUserId(addAppealDto.getUserId());
        LambdaQueryWrapper<AppealRecord> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(appealRecord.getArticleId() != null,AppealRecord::getArticleId, appealRecord.getArticleId());
        queryWrapper.eq(appealRecord.getAppealUserId() != null,AppealRecord::getAppealUserId, appealRecord.getAppealUserId());
        return baseMapper.selectOne(queryWrapper);
    }

    @Override
    public Result<?> getAppealRecordList(AppealRecordPageDto appealRecordPageDto) {
        Page<AppealRecordPageVo> page = new Page<>(appealRecordPageDto.getPage(),appealRecordPageDto.getLimit());
        baseMapper.selectPageRecord(page,appealRecordPageDto);
        if (page != null){
            return Result.ok(page);
        }
        return Result.fail("未查询到数据");
    }

}
